﻿using System;
using System.Linq;
using Missbot.Service;
using MongoDB.Bson.Serialization.Attributes;

namespace Missbot.AIModule.Gaming.Gift
{
    public class IntimateRelationshipRecord : DbBaseEntity
    {
        public string GroupID { get; init; }

        public string[] UserPair { get; init; }

        public int Value { get; init; }

        [BsonDateTimeOptions(Kind = DateTimeKind.Local)] public DateTime? ExpiryTime { get; set; }

        public string Name { get; set; }
    }

    public static class IntimateRelationshipDA
    {
        public static int GetSumIntimate(string GroupID, string firstUser, string secondUser)
        {
            var records = MongoService<IntimateRelationshipRecord>.Get(p => p.GroupID == GroupID &&
                                                                            p.UserPair.Contains(firstUser) &&
                                                                            p.UserPair.Contains(secondUser));
            return records.Sum(p => p.Value);
        }

        public static void Insert(this IntimateRelationshipRecord entity)
        {
            MongoService<IntimateRelationshipRecord>.Insert(entity);
        }
    }
}